package day13_net.com.itheima.d5_tcp2;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server1 {
    public static void main(String[] args) {
        try{
            System.out.println("服务器启动..");
            ServerSocket serverSocket = new ServerSocket(9999);
            Socket socket = serverSocket.accept();
            System.out.println("客户端连接成功");
            InputStream is = socket.getInputStream();
            DataInputStream dis = new DataInputStream(is);
            while (true){
                System.out.println("dis.readUTF() = " + dis.readUTF());
                System.out.println("socket.getInetAddress().getHostAddress() = " + socket.getInetAddress().getHostAddress());
                System.out.println("socket.getPort() = " + socket.getPort());
            }
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("程序出现异常，请稍后再试");
        }
    }
}
